#!/bin/bash
fn=""
test "$#" -ge 2 && fn="$2"
test "$#" -ge 1 || { echo "Usage: /path/to/create/link/on/./relative/path/to/link/to [linkname [extra args]]" ; exit 0 ; }
test "${1#./}" = "$1" && test "${1#*/./}" = "$1" &&\
 { echo "./ not present in path" ; exit 1 ; }
linkat="" ; linkto="${1#./}"
test "$linkto" = "$1" && { linkat="${1%%/./*}/"; linkto="${1#*/./}"; }
test -z "$linkto" && { echo "What do I link to?" ; exit 1 ; }
baseto="$(basename "$linkto")"
test -z "$fn" || baseto="$fn"
echo -n "Creating link $linkat$baseto to point to $linkto"
test "$#" -gt 2 && {
  echo -n ' with args "'
  printf '%q' "$3"
  test "$#" -gt 3 && printf ' %q' "${@:4}"
  echo -n '"';
}
echo
test -z "$linkat$fn" && linkat=./
set -x
ln -sT "${@:3}" "$linkto" "$linkat$baseto"
